<template>
	<view class="page">
		<view class="not-img" v-if="listData.length <= 0">
			<image class="not" src="../../static/not.png" mode=""></image>
			<view class="not-txt">
				暂无浏览记录
			</view>
		</view>


		<view class="main" v-else>

			<uni-swipe-action>
				<uni-swipe-action-item @click="bindClick" v-for="(item,index) in listData">

					<view class="content-box" @click="contentClick(item.id)">
						<view class="content-text">
							<!-- 插12312312313 -->
							<view class="content-item">

								<view class="left-img">
									<image class="avatar" :src="item.image" mode=""></image>
								</view>
								<view class="right-txt">
									<view class="right-txt-title">
										{{item.title}}
									</view>
									<view class="right-txt-date">
										{{item.date}}
									</view>
								</view>
							</view>
						</view>
					</view>
					<template v-slot:right>
						<view class="slot-button" @click="bindClick(index)"><text class="slot-button-text">删除</text>
						</view>
					</template>
				</uni-swipe-action-item>
			</uni-swipe-action>

		</view>
	</view>

	<!-- </view> -->
</template>

<script>
	export default {
		data() {
			return {
				listData: [],
				time: null,
				index: 0

			}
		},
		onLoad() {
			let arr;
			let localIdData = uni.getStorage({
				key: 'detailId',
				success: function(res) {
					// console.log(res.data)
					return arr = res.data
				}
			});
			if(arr.length != 0){
				this.loading();
			}else{
				return
			}
		},
		methods: {
			bindClick(index) {
				let newArr;
				let arr = uni.getStorage({
					key: 'detailId',
					success: function(res) {
						return newArr = res.data
					}
				});
				newArr.splice(index, 1)
				uni.setStorage({
					key: 'detailId',
					data: newArr,
					success: function() {
						// console.log('success');
					}
				});
				let that = this
				uni.setStorage({
					key: 'detailId',
					data: newArr,
					success: function() {
						// location.reload();
						// console.log("下标",that.index)
						that.index = 0
						that.listData = []
						that.loading()
					}
				});
			},
			contentClick(id) {
				uni.navigateTo({
					// url: `../home/detail?id=${id}`
					url: `../home/contentdetail?id=${id}`
				})
			},

			loading() {
				let arr;
				let localIdData = uni.getStorage({
					key: 'detailId',
					success: function(res) {
						// console.log(res.data)
						return arr = res.data
					}
				});
				// console.log(arr)
				if (arr.length != 0) {
				uni.request({
					url: `https://apis.netstart.cn/zhihudaily/story/${arr[this.index].contentid}`,
					success: res => {
						// console.log(res);
						this.listData.push({
							image: res.data.story.image,
							title: res.data.story.title,
							id: res.data.story.id,
							date: arr[this.index].time
						});
						if (this.index < arr.length - 1) {
							this.index++
							this.loading()
						} else {
							return
						}
					}
				})
				}else{
					return
				}
				// console.log("哈哈哈", this.listData)
			}
		}

	}
</script>

<style lang="less">
	// .main {
	// 	height: auto;
	// 	margin: 10px auto;
	// 	padding: 0 20rpx;
	// }

	.not-img {
		margin: 400rpx auto;
		text-align: center;

		.not {
			width: 148px;
			height: 110px;
		}

		.not-txt {
			margin-top: 20rpx;
			color: #ccc;
		}
	}

	.order-item {
		width: 100%;
		// display: flex;
		position: relative;
		margin: 10px auto;
		align-items: right;
		// flex-direction: row;
	}

	.item {
		background: #fff;
		border-radius: 10rpx 10rpx 10rpx;
		box-shadow: 0px 1px 4px #C0C0C0;
		display: flex;
		justify-content: space-between;
		font-size: 26rpx;
		color: #333;
		margin-bottom: 20rpx;
		padding: 24rpx 0 25rpx 0;
		position: relative;
	}

	.title {
		padding-left: 20rpx;
	}

	.model {
		position: absolute;
		top: 0;
		right: -50rpx;
		padding: 28rpx 26rpx;
		border-radius: 10rpx;
	}

	/deep/.uni-list-chat__content-note[data-v-3d9bc00b] {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		width: 290rpx;
		display: block;
	}

	/deep/.header--circle[data-v-3d9bc00b] {
		border-radius: 0;
	}

	/deep/.uni-list-chat__content-title[data-v-3d9bc00b] {
		// overflow: hidden;
		// text-overflow: ellipsis;
		// white-space: nowrap;
		// width: 500rpx;
		// display: block;
	}

	/deep/.uni-list-chat__content-extra[data-v-3d9bc00b] {
		display: inline;
	}


	.content-box {
		flex: 1;
		/* #ifdef APP-NVUE */
		justify-content: center;
		/* #endif */
		height: 44px;
		line-height: 44px;
		padding: 0 15px;
		position: relative;
		background-color: #fff;
		border-bottom-color: #f5f5f5;
		border-bottom-width: 1px;
		border-bottom-style: solid;
	}

	.content-item {
		display: flex;
	}

	.example-body {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		justify-content: center;
		padding: 10px 0;
		background-color: #fff;
	}

	.button {
		border-color: #e5e5e5;
		border-style: solid;
		border-width: 1px;
		padding: 4px 8px;
		border-radius: 4px;
	}

	.button-text {
		font-size: 15px;
	}

	.slot-button {
		/* #ifndef APP-NVUE */
		display: flex;
		height: 100%;
		/* #endif */
		flex: 1;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		padding: 0 20px;
		background-color: #ff5a5f;
	}

	.slot-button-text {
		color: #ffffff;
		font-size: 14px;
	}

	.content-box[data-v-835863d4] {
		height: 100%;
		line-height: 100%;
		margin-bottom: 20rpx;

	}

	.avatar {
		width: 200rpx;
		height: 200rpx;
	}

	.right-txt {
		padding: 20rpx 0 0 20rpx;
	}

	.right-txt-title {
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		line-clamp: 2;
		-webkit-box-orient: vertical;
	}

	.right-txt-date {
		margin-top: 30rpx;
		color: #C0C4CC;
	}
</style>
